import json

from tqdm import tqdm

import Config
from driver.driver import *
from public.public import entry_city, get_soldier_cities, get_special_soldier_cities

INCREASE_PERSONS = 1
RELIEF_PERSONS = 2
LUCKY_PERSONS = 3
GOD_PERSONS = 4

action_position = {
    RELIEF_PERSONS: (660, 310),  # 赈灾
    LUCKY_PERSONS: (660, 333),  # 祈福
    GOD_PERSONS: (660, 350),  # 祭天
    INCREASE_PERSONS: (660, 375),  # 增丁
}


def anfu_action(left, top, anfu_action):
    gov_position = (750, 250)
    mouse_move_to_and_click(left + gov_position[0], top + gov_position[1], time=1)
    an_fu_position = (590, 200)
    mouse_move_to_and_click(left + an_fu_position[0], top + an_fu_position[1])
    action_button = (690, 285)
    mouse_move_to_and_click(left + action_button[0], top + action_button[1])
    increase_position = action_position[anfu_action]
    mouse_move_to_and_click(left + increase_position[0], top + increase_position[1])
    increase_button = (620, 410)
    mouse_move_to_and_click(left + increase_button[0], top + increase_button[1])
    check_position = (590, 290)
    mouse_move_to_and_click(left + check_position[0], top + check_position[1])
    mouse_move_to_and_click(left + 920, top + 520)


def entry_def(action=INCREASE_PERSONS):
    control = get_control_by_level([0, 0, 0, 0, 0, 0], base_name="热血三国-")
    left, top, width, height = get_control_position(control)
    soldier_cities = []
    soldier_cities += get_soldier_cities(control)
    soldier_cities += get_special_soldier_cities(control)
    for _ in soldier_cities:
        entry_city(left, top, _[0], _[1], cityin=True)
        anfu_action(left, top, action)
    # anfu_action(left, top, action)


if __name__ == '__main__':
    count = 0
    while True:
        # entry_def(action=LUCKY_PERSONS)
        entry_def(action=INCREASE_PERSONS)
        count = (count % 14) + 1
        print("增丁{}次".format(count))
        for i in tqdm(range(60 * 15)):
            time.sleep(1)
